package com.springboot.cloud.authentication.controller;

import com.springboot.cloud.authentication.service.AuthenticationService;
import com.springboot.cloud.core.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p> 认证接口 </p>
 *
 * @author Bertram
 * @since 11/5/2019 3:23 PM
 */
@RestController
@Slf4j
public class AuthenticationController {

    private AuthenticationService authenticationService;

    public AuthenticationController(AuthenticationService authenticationService) {
        this.authenticationService = authenticationService;
    }

    /**
     * 判断请求是否拥有权限
     * @param url
     * @param method
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/auth/permission")
    public Result decide(@RequestParam String url, @RequestParam String method, HttpServletRequest request) {
        boolean decide = authenticationService.decide(new HttpServletRequestAuthWrapper(request, url, method));
        return Result.success(decide);
    }

}
